********************************************************************************
********************************************************************************
***                                                                          *** 
***                            Replication do file                           ***
***                                                                          ***
*** This do file replicates all tables and figures in the paper "Public      ***
*** Services and the Geography of Citizen Perceptions of Government in Latin ***
*** America and the Caribbean," as well as the Appendix.                     ***
***                                                                          ***
***                                                                          ***
********************************************************************************
********************************************************************************
clear

ssc install estout, replace

* change your working directory:
*cd " "

* import data
import delimited "LAPOP2014_distances.csv"

*Activating survey weights
svyset pais [pweight=weight1500]

********************************************************************************
***                                                                          ***
***              Replicates: Tables and Figures within the paper             ***
***                                                                          ***
*** Note: the code to generate tables and figures is listed here in the      ***
***       in which they appear in the paper.                                 ***
***                                                                          ***
********************************************************************************


********************************************************************************
***                          Figure 2 and Table 1                            ***
********************************************************************************

* MAIN MODEL using average service satisfaction
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##c.sat_avg i.pais [pweight= weight1500], vce(cluster pais)
eststo column_1

lincom c.sat_avg#c.km_to_nid_15000 + c.sat_avg#c.km_to_nid_15000#c.km_to_nid_15000

* Fig 2, Panel A, left
margins, at(sat_avg= (1.75 (.25) 3.25) km_to_nid_15000 = (0 35))
marginsplot

* Fig 2, Panel A, right
margins, at(km_to_nid_15000= (0 (5) 35) sat_avg = (1.75 3.25))
marginsplot


** MAIN MODEL using satisfaction with each service:

* (Dis) Satisfaction with the police (pole2n: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##pole2n i.pais [pweight= weight1500], vce(cluster pais)
eststo column_2

lincom 4.pole2n#c.km_to_nid_15000 + 4.pole2n#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.pole2n#c.km_to_nid_15000 + 3.pole2n#c.km_to_nid_15000#c.km_to_nid_15000

* Fig 2, Panel B, top left
margins, at(km_to_nid_15000= (0 (5) 35) pole2n = (1 4))
marginsplot


* (Dis) Satisfaction with trasportation infrastructure (sd2new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd2new2 i.pais [pweight= weight1500], vce(cluster pais) 
eststo column_3

lincom 4.sd2new2#c.km_to_nid_15000 + 4.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd2new2#c.km_to_nid_15000 + 3.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000

* Fig 2, Panel B, top right
margins, at(km_to_nid_15000= (0 (5) 35) sd2new2 = (1 4))
marginsplot


* (Dis) Satisfaction with public schools (sd3new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd3new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_4

lincom 4.sd3new2#c.km_to_nid_15000 + 4.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd3new2#c.km_to_nid_15000 + 3.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000

* Fig 2, Panel B, bottom left
margins, at(km_to_nid_15000= (0 (5) 35) sd3new2 = (1 4))
marginsplot


* (Dis) Satisfaction with public healthcare (sd6new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd6new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_5

lincom 4.sd6new2#c.km_to_nid_15000 + 4.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd6new2#c.km_to_nid_15000 + 3.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000

* Fig 2, Panel B, bottom right
margins, at(km_to_nid_15000= (0 (5) 35) sd6new2 = (1 4))
marginsplot


* Generating Table 1
esttab column_1 column_2 column_3 column_4 column_5 using table1.tex, label se pr2 aic title(Service Satisfaction, Distance to cities of at least 15,000 inhabitants, and Approval of the President/Prime Minister)
eststo clear


********************************************************************************
***                                Figure 3                                  ***
********************************************************************************

* Trust; using average service satisfaction
xi: logit trust_cgov c.km_to_nid_15000##c.km_to_nid_15000##c.sat_avg i.pais [pweight= weight1500], vce(cluster pais)

* Fig 3, Panel A, left
margins, at(sat_avg= (1.75 (.25) 3.25) km_to_nid_15000 = (0 35))
marginsplot

* Fig 3, Panel A, right
margins, at(km_to_nid_15000= (0 (5) 35) sat_avg = (1.75 3.25))
marginsplot


** Trust; using satisfaction with each service:

* (Dis) Satisfaction with the police (pole2n: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_15000##c.km_to_nid_15000##pole2n i.pais [pweight= weight1500], vce(cluster pais)

* Fig 3, Panel B, top left
margins, at(km_to_nid_15000= (0 (5) 35) pole2n = (1 4))
marginsplot


* (Dis) Satisfaction with trasportation infrastructure (sd2new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_15000##c.km_to_nid_15000##sd2new2 i.pais [pweight= weight1500], vce(cluster pais) 

* Fig 3, Panel B, top right
margins, at(km_to_nid_15000= (0 (5) 35) sd2new2 = (1 4))
marginsplot


* (Dis) Satisfaction with public schools (sd3new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_15000##c.km_to_nid_15000##sd3new2 i.pais [pweight= weight1500], vce(cluster pais)

* Fig 3, Panel B, bottom left
margins, at(km_to_nid_15000= (0 (5) 35) sd3new2 = (1 4))
marginsplot


* (Dis) Satisfaction with public healthcare (sd6new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_15000##c.km_to_nid_15000##sd6new2 i.pais [pweight= weight1500], vce(cluster pais)

* Fig 3, Panel B, bottom right
margins, at(km_to_nid_15000= (0 (5) 35) sd6new2 = (1 4))
marginsplot


********************************************************************************
***                                Table 2                                   ***
********************************************************************************

* FIRST STAGE of the mediation procedure for the mechanisms:       

* State Capacity
xi: reg sc_c1 c.km_to_nid_15000##c.km_to_nid_15000 i.pais [pweight= weight1500], vce(cluster pais)
lincom km_to_nid_15000 + c.km_to_nid_15000#c.km_to_nid_15000

eststo m1


* Political Knowledge 
xi: reg pk_c1 c.km_to_nid_15000##c.km_to_nid_15000 i.pais [pweight= weight1500], vce(cluster pais)
lincom km_to_nid_15000 + c.km_to_nid_15000#c.km_to_nid_15000

eststo m2


* Deference to Hierarchy
xi: reg dh_c1 c.km_to_nid_15000##c.km_to_nid_15000 i.pais [pweight= weight1500], vce(cluster pais)
lincom km_to_nid_15000 + c.km_to_nid_15000#c.km_to_nid_15000

eststo m3

* Low Political Efficacy
xi: reg mech4_c1 c.km_to_nid_15000##c.km_to_nid_15000 i.pais [pweight= weight1500], vce(cluster pais)
lincom km_to_nid_15000 + c.km_to_nid_15000#c.km_to_nid_15000

eststo m4

* Generating Table 2:
esttab m1 m2 m6 m7 m8 using table2.tex, label se r2 title(First Stage of the Mediation Analysis)
eststo clear


********************************************************************************
***                                Figure 4                                  ***
********************************************************************************

* Low political efficacy
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##c.sat_avg c.mech4_c1##c.sat_avg i.pais [pweight= weight1500], vce(cluster pais)

* Fig 4, Panel A, left
margins, at(sat_avg= (1.75 (.25) 3.25) km_to_nid_15000 = (0 35))
marginsplot

* Fig 4, Panel A, right
margins, at(km_to_nid_15000= (0 (5) 35) sat_avg = (1.75 3.25))
marginsplot


* Deference to hierarchy
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##c.sat_avg c.dh_c1##c.sat_avg i.pais [pweight= weight1500], vce(cluster pais)

* Fig 4, Panel B, left
margins, at(sat_avg= (1.75 (.25) 3.25) km_to_nid_15000 = (0 35))
marginsplot

* Fig 4, Panel B, right
margins, at(km_to_nid_15000= (0 (5) 35) sat_avg = (1.75 3.25))
marginsplot






********************************************************************************
***                                                                          ***
***                Replicates: Appendix Figures and Tables                   ***
***                                                                          ***
********************************************************************************


********************************************************************************
***                Appendix Table A1: Descriptive Statistics                 ***
********************************************************************************

estpost summarize km_to_nid_15000 exec_perf trust_cgov pole2n sd2new2 sd3new2 sd6new2 edad eduy female poor
esttab using sum1.tex , cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2)) min(fmt(1)) max(fmt(1))") nomtitle nonumber replace


********************************************************************************
***                 Appendix Table A2 and Appendix Figure A2                 ***
********************************************************************************

* Approval of the President/Prime Minister
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_1

* Appendix Fig. A2, left 
margins, at(km_to_nid_15000= (0 (5) 35))
marginsplot


* Trust in the President/Prime Minister
xi: logit trust_cgov c.km_to_nid_15000##c.km_to_nid_15000 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_2

* Appendix Fig. A2, right
margins, at(km_to_nid_15000= (0 (5) 35))
marginsplot


* Generating Table A2
esttab column_1 column_2 using tableA2.tex, label se r2 title(Approval of and Trust in the President/Prime Minister and Distance to cities of at least 15,000 inhabitants)
eststo clear


********************************************************************************
***                            Appendix Figure A1                            ***
********************************************************************************

* Histogram of distance
summarize km_to_nid_15000, detail
histogram km_to_nid_15000, xline(`r(mean)')



********************************************************************************
***                            Appendix Figure A3                            ***
********************************************************************************
* Service Satisfaction, Distance and Trust in the Municipal Government

* (Dis) Satisfaction with the police (pole2n: 1=very satisfied, 4=very disatisfied)
xi: logit trust_mun c.km_to_nid_15000##c.km_to_nid_15000##pole2n i.pais [pweight= weight1500], vce(cluster pais)

* Appendix Fig A3, top left
margins, at(pole2n = (1 (1) 4) km_to_nid_15000= (0 35))
marginsplot


* (Dis) Satisfaction with trasportation infrastructure (sd2new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_mun c.km_to_nid_15000##c.km_to_nid_15000##sd2new2 i.pais [pweight= weight1500], vce(cluster pais) 

* Appendix Fig A3, top right
margins, at(sd2new2 = (1 (1) 4) km_to_nid_15000= (0 35))
marginsplot


* (Dis) Satisfaction with public schools (sd3new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_mun c.km_to_nid_15000##c.km_to_nid_15000##sd3new2 i.pais [pweight= weight1500], vce(cluster pais)

* Appendix Fig A3, bottom left
margins, at(sd3new2 = (1 (1) 4) km_to_nid_15000= (0 35))
marginsplot


* (Dis) Satisfaction with public healthcare (sd6new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_mun c.km_to_nid_15000##c.km_to_nid_15000##sd6new2 i.pais [pweight= weight1500], vce(cluster pais)

* Appendix Fig A3, bottom right
margins, at(sd6new2 = (1 (1) 4) km_to_nid_15000= (0 35))
marginsplot

********************************************************************************
***                            Appendix Figure A4                            ***
********************************************************************************
* Non parametric representation of the relation between service satisfaction and 
* approval of the president/prime minister at high and low distance from urban centers

* Defining high and low distance:

* 1. high distance: above 75 percentile of distance; low distance: below 25 percintile of distance
gen near_cities=.
replace near_cities = 1 if km_to_nid_15000 <= 2.074757 
replace near_cities = 0 if km_to_nid_15000 >= 11.56738 

* 2. high distance: above median distance; low distance: below median distance
gen near_cities2=.
replace near_cities2 = 1 if km_to_nid_15000 <= 4.927462
replace near_cities2 = 0 if km_to_nid_15000 > 4.927462

* Appendix Fig A4, left
lowess exec_perf sat_avg, by(near_cities)

* Appendix Fig A4, right
lowess exec_perf sat_avg, by(near_cities2)

********************************************************************************
***         Appendix Table B1 and Appendix Figures B1, B4, B5 and B6         ***
********************************************************************************

* Column 1: Main model

* MAIN MODEL with CONTROLS
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##c.sat_avg [pweight= weight1500], vce(cluster pais)
eststo column_1

lincom c.sat_avg#c.km_to_nid_15000 + c.sat_avg#c.km_to_nid_15000#c.km_to_nid_15000


* Column 2: Main model with controls

* MAIN MODEL with CONTROLS
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##c.sat_avg edad eduy female poor i.pais [pweight= weight1500], vce(cluster pais)
eststo column_2

lincom c.sat_avg#c.km_to_nid_15000 + c.sat_avg#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B1, Left
margins, at(sat_avg= (1.75 (.25) 3.25) km_to_nid_15000 = (0 35))
marginsplot

* Appendix Figure B1, Right
margins, at(km_to_nid_15000= (0 (5) 35) sat_avg = (1.75 3.25))
marginsplot


* Column 3: Federal (Mexico)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##c.sat_avg i.prov if pais == 1
eststo column_3
estat ic

lincom c.sat_avg#c.km_to_nid_15000 + c.sat_avg#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B5, Panel A, Left
margins, at(sat_avg= (1.75 (.25) 3.25) km_to_nid_15000 = (0 25))
marginsplot

* Appendix Figure B5, Panel A, Right
margins, at(km_to_nid_15000= (0 (5) 25) sat_avg = (1.75 3.25))
marginsplot



* Column 4: Decentralized (Colombia)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##c.sat_avg i.prov if pais == 8
eststo column_4
estat ic

lincom c.sat_avg#c.km_to_nid_15000 + c.sat_avg#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B5, Panel B, Left
margins, at(sat_avg= (1.75 (.25) 3.25) km_to_nid_15000 = (0 25))
marginsplot

* Appendix Figure B5, Panel B, Right
margins, at(km_to_nid_15000= (0 (5) 25) sat_avg = (1.75 3.25))
marginsplot


* Column 5: Unitary
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##c.sat_avg i.pais [pweight= weight1500] if pais != 1, vce(cluster pais)
eststo column_5

lincom c.sat_avg#c.km_to_nid_15000 + c.sat_avg#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B5, Panel C, Left
margins, at(sat_avg= (1.75 (.25) 3.25) km_to_nid_15000 = (0 35))
marginsplot

* Appendix Figure B5, Panel C, Rigth
margins, at(km_to_nid_15000= (0 (5) 35) sat_avg = (1.75 3.25))
marginsplot


* Column 6: Rural dummy
xi: logit exec_perf rural##c.sat_avg i.pais [pweight= weight1500], vce(cluster pais)
eststo column_6

* Appendix Figure B4, Left
margins, at(sat_avg= (1.75 (.25) 3.25) rural = (0 1))
marginsplot


* Column 7: Location size
xi: logit exec_perf tamano##c.sat_avg i.pais [pweight= weight1500], vce(cluster pais)
eststo m_popsz 

* Appendix Figure B4, Right
margins, at(tamano= (1 (1) 5) sat_avg = (1.75 3.25))
marginsplot



* Column 8: Trust as dv
xi: logit trust_cgov c.km_to_nid_15000##c.km_to_nid_15000##c.sat_avg i.pais [pweight= weight1500], vce(cluster pais)
eststo column_8

lincom c.sat_avg#c.km_to_nid_15000 + c.sat_avg#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B6, top left
margins, at(km_to_nid_15000= (0 (5) 35) sat_avg = (1.75 3.25))
marginsplot


* Column 9: Trust as dv, with controls
xi: logit trust_cgov c.km_to_nid_15000##c.km_to_nid_15000##c.sat_avg edad eduy female poor i.pais [pweight= weight1500], vce(cluster pais)
eststo column_9

lincom c.sat_avg#c.km_to_nid_15000 + c.sat_avg#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B6, top rigth
margins, at(km_to_nid_15000= (0 (5) 35) sat_avg = (1.75 3.25))
marginsplot


* Generating Table B1
esttab column_1 column_2 column_3 column_4 column_5 column_6 column_7 column_8 column_9 using tableB1.tex, label se r2 title(Service Satisfaction, Distance to cities of at least 15,000 inhabitants, Approval and Trust)
eststo clear


********************************************************************************
***           Appendix Table B2 and Appendix Figures B2, B3 and B6           ***
********************************************************************************

* Column 1: Main model with distance to cities of 5,000 inhabitans 
xi: logit exec_perf c.km_to_nid_5000##c.km_to_nid_5000##c.sat_avg i.pais [pweight= weight1500], vce(cluster pais)
eststo column_1

lincom c.sat_avg#c.km_to_nid_5000 + c.sat_avg#c.km_to_nid_5000#c.km_to_nid_5000

* Appendix Figure B3, Left
margins, at(km_to_nid_5000= (0 (4) 16) sat_avg = (1.75 3.25))
marginsplot

* Column 2: Trust as DV and distance to cities of 5,000 inhabitans 
xi: logit trust_cgov c.km_to_nid_5000##c.km_to_nid_5000##c.sat_avg i.pais [pweight= weight1500], vce(cluster pais)
eststo column_2

lincom c.sat_avg#c.km_to_nid_5000 + c.sat_avg#c.km_to_nid_5000#c.km_to_nid_5000

* Appendix Figure B3, Rigt Appendix B6 bottom left
margins, at(km_to_nid_5000= (0 (4) 16) sat_avg = (1.75 3.25))
marginsplot

* Column 3: Main model with distance to capital cities 
xi: logit exec_perf c.km_to_nid_cap##c.km_to_nid_cap##c.sat_avg i.pais [pweight= weight1500], vce(cluster pais)
eststo column_3

lincom c.sat_avg#c.km_to_nid_cap + c.sat_avg#c.km_to_nid_cap#c.km_to_nid_cap

* Appendix Figure B2, Left
margins, at(km_to_nid_cap= (0 (16) 112) sat_avg = (1.75 3.25))
marginsplot


* Column 4: Trust as DV and distance to capital cities
xi: logit trust_cgov c.km_to_nid_cap##c.km_to_nid_cap##c.sat_avg i.pais [pweight= weight1500], vce(cluster pais)
eststo column_4

lincom c.sat_avg#c.km_to_nid_cap + c.sat_avg#c.km_to_nid_cap#c.km_to_nid_cap

* Appendix Figure B2, Right & Appendix B6 bottom right
margins, at(km_to_nid_cap= (0 (16) 112) sat_avg = (1.75 3.25))
marginsplot

* Generating Table B2
esttab column_1 column_2 column_3 column_4 using tableB2.tex, label se pr2 aic title(Service Satisfaction, Distance, Approval and Trust)
eststo clear



********************************************************************************
***                  Appendix Table B3 and Appendix Figure B7                ***
********************************************************************************

** MAIN MODEL using satisfaction with each service and adding demographic controls

* (Dis) Satisfaction with the police (pole2n: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##pole2n edad eduy female poor i.pais [pweight= weight1500], vce(cluster pais)
eststo column_1

lincom 4.pole2n#c.km_to_nid_15000 + 4.pole2n#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.pole2n#c.km_to_nid_15000 + 3.pole2n#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B7, top left
margins, at(km_to_nid_15000= (0 (5) 35) pole2n = (1 4))
marginsplot


* (Dis) Satisfaction with trasportation infrastructure (sd2new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd2new2 edad eduy female poor i.pais [pweight= weight1500], vce(cluster pais) 
eststo column_2

lincom 4.sd2new2#c.km_to_nid_15000 + 4.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd2new2#c.km_to_nid_15000 + 3.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B7, top right
margins, at(km_to_nid_15000= (0 (5) 35) sd2new2 = (1 4))
marginsplot


* (Dis) Satisfaction with public schools (sd3new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd3new2 edad eduy female poor i.pais [pweight= weight1500], vce(cluster pais)
eststo column_3

lincom 4.sd3new2#c.km_to_nid_15000 + 4.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd3new2#c.km_to_nid_15000 + 3.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B7, bottom left
margins, at(km_to_nid_15000= (0 (5) 35) sd3new2 = (1 4))
marginsplot


* (Dis) Satisfaction with public healthcare (sd6new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd6new2 edad eduy female poor i.pais [pweight= weight1500], vce(cluster pais)
eststo column_4

lincom 4.sd6new2#c.km_to_nid_15000 + 4.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd6new2#c.km_to_nid_15000 + 3.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B7, bottom right
margins, at(km_to_nid_15000= (0 (5) 35) sd6new2 = (1 4))
marginsplot


** TRUST AS DV, using satisfaction with each service and adding demographic controls

* (Dis) Satisfaction with the police (pole2n: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_15000##c.km_to_nid_15000##pole2n edad eduy female poor i.pais [pweight= weight1500], vce(cluster pais)
eststo column_5

lincom 4.pole2n#c.km_to_nid_15000 + 4.pole2n#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.pole2n#c.km_to_nid_15000 + 3.pole2n#c.km_to_nid_15000#c.km_to_nid_15000

* (Dis) Satisfaction with trasportation infrastructure (sd2new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_15000##c.km_to_nid_15000##sd2new2 edad eduy female poor i.pais [pweight= weight1500], vce(cluster pais) 
eststo column_6

lincom 4.sd2new2#c.km_to_nid_15000 + 4.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd2new2#c.km_to_nid_15000 + 3.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000

* (Dis) Satisfaction with public schools (sd3new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_15000##c.km_to_nid_15000##sd3new2 edad eduy female poor i.pais [pweight= weight1500], vce(cluster pais)
eststo column_7

lincom 4.sd3new2#c.km_to_nid_15000 + 4.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd3new2#c.km_to_nid_15000 + 3.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000

* (Dis) Satisfaction with public healthcare (sd6new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_15000##c.km_to_nid_15000##sd6new2 edad eduy female poor i.pais [pweight= weight1500], vce(cluster pais)
eststo column_8

lincom 4.sd6new2#c.km_to_nid_15000 + 4.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd6new2#c.km_to_nid_15000 + 3.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000

* Generating Table B3
esttab column_1 column_2 column_3 column_4 column_5 column_6 column_7 column_8 using tableB3.tex, label se pr2 aic title(Service Satisfaction, Distance to Cities of 15,000 Inhabitants, Approval and Trust (with Demographic Controls))
eststo clear


********************************************************************************
***             Appendix Table B4 and Appendix Figures B8 and B9             ***
********************************************************************************

** MAIN MODEL using satisfaction with each service and distance to the capital city

* (Dis) Satisfaction with the police (pole2n: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_cap##c.km_to_nid_cap##pole2n i.pais [pweight= weight1500], vce(cluster pais)
eststo column_1

lincom 4.pole2n#c.km_to_nid_cap + 4.pole2n#c.km_to_nid_cap#c.km_to_nid_cap
lincom 3.pole2n#c.km_to_nid_cap + 3.pole2n#c.km_to_nid_cap#c.km_to_nid_cap

* Appendix Figure B8, top left
margins, at(km_to_nid_cap = (0 (16) 112) pole2n = (1 4))
marginsplot


* (Dis) Satisfaction with trasportation infrastructure (sd2new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_cap##c.km_to_nid_cap##sd2new2 i.pais [pweight= weight1500], vce(cluster pais) 
eststo column_2

lincom 4.sd2new2#c.km_to_nid_cap + 4.sd2new2#c.km_to_nid_cap#c.km_to_nid_cap
lincom 3.sd2new2#c.km_to_nid_cap + 3.sd2new2#c.km_to_nid_cap#c.km_to_nid_cap

* Appendix Figure B8, top right
margins, at(km_to_nid_cap = (0 (16) 112) sd2new2 = (1 4))
marginsplot


* (Dis) Satisfaction with public schools (sd3new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_cap##c.km_to_nid_cap##sd3new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_3

lincom 4.sd3new2#c.km_to_nid_cap + 4.sd3new2#c.km_to_nid_cap#c.km_to_nid_cap
lincom 3.sd3new2#c.km_to_nid_cap + 3.sd3new2#c.km_to_nid_cap#c.km_to_nid_cap

* Appendix Figure B8, bottom left
margins, at(km_to_nid_cap = (0 (16) 112) sd3new2 = (1 4))
marginsplot


* (Dis) Satisfaction with public healthcare (sd6new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_cap##c.km_to_nid_cap##sd6new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_4

lincom 4.sd6new2#c.km_to_nid_cap + 4.sd6new2#c.km_to_nid_cap#c.km_to_nid_cap
lincom 3.sd6new2#c.km_to_nid_cap + 3.sd6new2#c.km_to_nid_cap#c.km_to_nid_cap

* Appendix Figure B8, bottom right
margins, at(km_to_nid_cap = (0 (16) 112) sd6new2 = (1 4))
marginsplot


** TRUST AS DV, using satisfaction with each service and distance to the capital city

* (Dis) Satisfaction with the police (pole2n: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_cap##c.km_to_nid_cap##pole2n i.pais [pweight= weight1500], vce(cluster pais)
eststo column_5

lincom 4.pole2n#c.km_to_nid_cap + 4.pole2n#c.km_to_nid_cap#c.km_to_nid_cap
lincom 3.pole2n#c.km_to_nid_cap + 3.pole2n#c.km_to_nid_cap#c.km_to_nid_cap

* Appendix Figure B9, top left
margins, at(km_to_nid_cap = (0 (16) 112) pole2n = (1 4))
marginsplot

* (Dis) Satisfaction with trasportation infrastructure (sd2new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_cap##c.km_to_nid_cap##sd2new2 i.pais [pweight= weight1500], vce(cluster pais) 
eststo column_6

lincom 4.sd2new2#c.km_to_nid_cap + 4.sd2new2#c.km_to_nid_cap#c.km_to_nid_cap
lincom 3.sd2new2#c.km_to_nid_cap + 3.sd2new2#c.km_to_nid_cap#c.km_to_nid_cap

* Appendix Figure B9, top right
margins, at(km_to_nid_cap = (0 (16) 112) sd2new2 = (1 4))
marginsplot

* (Dis) Satisfaction with public schools (sd3new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_cap##c.km_to_nid_cap##sd3new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_7

lincom 4.sd3new2#c.km_to_nid_cap + 4.sd3new2#c.km_to_nid_cap#c.km_to_nid_cap
lincom 3.sd3new2#c.km_to_nid_cap + 3.sd3new2#c.km_to_nid_cap#c.km_to_nid_cap

* Appendix Figure B9, bottom left
margins, at(km_to_nid_cap = (0 (16) 112) sd3new2 = (1 4))
marginsplot

* (Dis) Satisfaction with public healthcare (sd6new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_cap##c.km_to_nid_cap##sd6new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_8

lincom 4.sd6new2#c.km_to_nid_cap + 4.sd6new2#c.km_to_nid_cap#c.km_to_nid_cap
lincom 3.sd6new2#c.km_to_nid_cap + 3.sd6new2#c.km_to_nid_cap#c.km_to_nid_cap

* Appendix Figure B9, bottom right
margins, at(km_to_nid_cap = (0 (16) 112) sd6new2 = (1 4))
marginsplot

* Generating Table B4
esttab column_1 column_2 column_3 column_4 column_5 column_6 column_7 column_8 using tableB4.tex, label se pr2 aic title(Service Satisfaction, Distance to Capital Cities, Approval and Trust)
eststo clear



********************************************************************************
***            Appendix Table B5 and Appendix Figures B10 and B11            ***
********************************************************************************

** MAIN MODEL using satisfaction with each service and adding demographic controls

* (Dis) Satisfaction with the police (pole2n: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_5000##c.km_to_nid_5000##pole2n i.pais [pweight= weight1500], vce(cluster pais)
eststo column_1

lincom 4.pole2n#c.km_to_nid_5000 + 4.pole2n#c.km_to_nid_5000#c.km_to_nid_5000
lincom 3.pole2n#c.km_to_nid_5000 + 3.pole2n#c.km_to_nid_5000#c.km_to_nid_5000

* Appendix Figure B10, top left
margins, at(km_to_nid_5000= (0 (4) 16) pole2n = (1 4))
marginsplot


* (Dis) Satisfaction with trasportation infrastructure (sd2new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_5000##c.km_to_nid_5000##sd2new2 i.pais [pweight= weight1500], vce(cluster pais) 
eststo column_2

lincom 4.sd2new2#c.km_to_nid_5000 + 4.sd2new2#c.km_to_nid_5000#c.km_to_nid_5000
lincom 3.sd2new2#c.km_to_nid_5000 + 3.sd2new2#c.km_to_nid_5000#c.km_to_nid_5000

* Appendix Figure B10, top right
margins, at(km_to_nid_5000= (0 (4) 16) sd2new2 = (1 4))
marginsplot


* (Dis) Satisfaction with public schools (sd3new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_5000##c.km_to_nid_5000##sd3new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_3

lincom 4.sd3new2#c.km_to_nid_5000 + 4.sd3new2#c.km_to_nid_5000#c.km_to_nid_5000
lincom 3.sd3new2#c.km_to_nid_5000 + 3.sd3new2#c.km_to_nid_5000#c.km_to_nid_5000

* Appendix Figure B10, bottom left
margins, at(km_to_nid_5000= (0 (4) 16) sd3new2 = (1 4))
marginsplot


* (Dis) Satisfaction with public healthcare (sd6new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_5000##c.km_to_nid_5000##sd6new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_4

lincom 4.sd6new2#c.km_to_nid_5000 + 4.sd6new2#c.km_to_nid_5000#c.km_to_nid_5000
lincom 3.sd6new2#c.km_to_nid_5000 + 3.sd6new2#c.km_to_nid_5000#c.km_to_nid_5000

* Appendix Figure B10, bottom right
margins, at(km_to_nid_5000= (0 (4) 16) sd6new2 = (1 4))
marginsplot


** TRUST AS DV, using satisfaction with each service and adding demographic controls

* (Dis) Satisfaction with the police (pole2n: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_5000##c.km_to_nid_5000##pole2n i.pais [pweight= weight1500], vce(cluster pais)
eststo column_5

lincom 4.pole2n#c.km_to_nid_5000 + 4.pole2n#c.km_to_nid_5000#c.km_to_nid_5000
lincom 3.pole2n#c.km_to_nid_5000 + 3.pole2n#c.km_to_nid_5000#c.km_to_nid_5000

* Appendix Figure B11, top left
margins, at(km_to_nid_5000= (0 (4) 16) pole2n = (1 4))
marginsplot

* (Dis) Satisfaction with trasportation infrastructure (sd2new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_5000##c.km_to_nid_5000##sd2new2 i.pais [pweight= weight1500], vce(cluster pais) 
eststo column_6

lincom 4.sd2new2#c.km_to_nid_5000 + 4.sd2new2#c.km_to_nid_5000#c.km_to_nid_5000
lincom 3.sd2new2#c.km_to_nid_5000 + 3.sd2new2#c.km_to_nid_5000#c.km_to_nid_5000

* Appendix Figure B11, top right
margins, at(km_to_nid_5000= (0 (4) 16) sd2new2 = (1 4))
marginsplot

* (Dis) Satisfaction with public schools (sd3new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_5000##c.km_to_nid_5000##sd3new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_7

lincom 4.sd3new2#c.km_to_nid_5000 + 4.sd3new2#c.km_to_nid_5000#c.km_to_nid_5000
lincom 3.sd3new2#c.km_to_nid_5000 + 3.sd3new2#c.km_to_nid_5000#c.km_to_nid_5000

* Appendix Figure B11, bottom left
margins, at(km_to_nid_5000= (0 (4) 16) sd3new2 = (1 4))
marginsplot

* (Dis) Satisfaction with public healthcare (sd6new2: 1=very satisfied, 4=very disatisfied)
xi: logit trust_cgov c.km_to_nid_5000##c.km_to_nid_5000##sd6new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_8

lincom 4.sd6new2#c.km_to_nid_5000 + 4.sd6new2#c.km_to_nid_5000#c.km_to_nid_5000
lincom 3.sd6new2#c.km_to_nid_5000 + 3.sd6new2#c.km_to_nid_5000#c.km_to_nid_5000

* Appendix Figure B10, bottom right
margins, at(km_to_nid_5000= (0 (4) 16) sd6new2 = (1 4))
marginsplot

* Generating Table B5
esttab column_1 column_2 column_3 column_4 column_5 column_6 column_7 column_8 using tableB5.tex, label se pr2 aic title(Service Satisfaction, Distance to Cities of 5,000 Inhabitants, Approval and Trust (with Demographic Controls))
eststo clear



********************************************************************************
***                Appendix Table B6 and Appendix Figures B12                ***
********************************************************************************
** MAIN MODEL using satisfaction with each service and using a rural area dummy instead of distance to cities:

*First: pole2n - Satisfaction with the police (1=very satisfied, 4=very disatisfied)
xi: logit exec_perf rural##pole2n i.pais [pweight= weight1500], vce(cluster pais)
eststo column_1

* Appendix Figure B12, top left
margins, at(pole2n= (1 (1) 4) rural = (0 1))
marginsplot

*Second: sd2new2 - Satisfaction with trasportation infrastructure  (1=very satisfied, 4=very disatisfied)
xi: logit exec_perf rural##sd2new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_2

* Appendix Figure B12, top right
margins, at(sd2new2= (1 (1) 4) rural = (0 1))
marginsplot

* Third: sd3new2 - Satisfaction with public schools (1=very satisfied, 4=very disatisfied)
xi: logit exec_perf rural##sd3new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_3

* Appendix Figure B12, bottom left
margins, at(sd3new2= (1 (1) 4) rural = (0 1))
marginsplot

* Fourth: sd6new2 - Satisfaction with public health (1=very satisfied, 4=very disatisfied)
xi: logit exec_perf rural##sd6new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_4

* Appendix Figure B12, bottom right
margins, at(sd6new2= (1 (1) 4) rural = (0 1))
marginsplot

* Generating Table B6
esttab column_1 column_2 column_3 column_4 using tableB6.tex, label se pr2 aic title(Service Satisfaction, Rurality Dummy, and Approval of the President/Prime Minister)
eststo clear


********************************************************************************
***                Appendix Table B7 and Appendix Figures B13                ***
********************************************************************************
** MAIN MODEL using satisfaction with each service and using a population size instead of distance to cities:
* Variable tamano: 1 == capital city, 2 == large city, 3 == med city, 4 == small city; 5 == rural area

*First: pole2n - Satisfaction with the police (1=very satisfied, 4=very disatisfied)
xi: logit exec_perf tamano##pole2n i.pais [pweight= weight1500], vce(cluster pais)
eststo tamano_pol

* Appendix Figure B13, top left
margins, at(tamano = (1 (1) 5) pole2n=(1 4))
marginsplot

*Second: sd2new2 - Satisfaction with trasportation infrastructure  (1=very satisfied, 4=very disatisfied)
xi: logit exec_perf tamano##sd2new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo tamano_inf

* Appendix Figure B13, top right
margins, at(tamano = (1 (1) 5) sd2new2=(1 4))
marginsplot

* Third: sd3new2 - Satisfaction with public schools (1=very satisfied, 4=very disatisfied)
xi: logit exec_perf tamano##sd3new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo tamano_edu

* Appendix Figure B13, bottom left
margins, at(tamano = (1 (1) 5) sd3new2=(1 4))
marginsplot

* Fourth: sd6new2 - Satisfaction with public health (1=very satisfied, 4=very disatisfied)
xi: logit exec_perf tamano##sd6new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo tamano_hel

* Appendix Figure B13, bottom right
margins, at(tamano = (1 (1) 5) sd6new2=(1 4))
marginsplot

* Generating Table B7
esttab column_1 column_2 column_3 column_4 using tableB7.tex, label se pr2 aic title(Service Satisfaction, Population Size, and Approval of the President/Prime Minister)
eststo clear


********************************************************************************
***                Appendix Table B8 and Appendix Figure B14                 ***
********************************************************************************
* Sample of Unitary countries (without Colombia)
gen unitary=.
replace unitary = 1 if pais != 1 | pais != 8
replace unitary = 0 if pais == 1 | pais == 8

** MAIN MODEL using satisfaction with each service:

* (Dis) Satisfaction with the police (pole2n: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##pole2n i.pais [pweight= weight1500] if unitary == 1, vce(cluster pais)
eststo column_1

lincom 4.pole2n#c.km_to_nid_15000 + 4.pole2n#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.pole2n#c.km_to_nid_15000 + 3.pole2n#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B14, top left
margins, at(km_to_nid_15000= (0 (5) 35) pole2n = (1 4))
marginsplot


* (Dis) Satisfaction with trasportation infrastructure (sd2new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd2new2 i.pais [pweight= weight1500] if unitary == 1, vce(cluster pais) 
eststo column_2

lincom 4.sd2new2#c.km_to_nid_15000 + 4.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd2new2#c.km_to_nid_15000 + 3.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B14, top right
margins, at(km_to_nid_15000= (0 (5) 35) sd2new2 = (1 4))
marginsplot


* (Dis) Satisfaction with public schools (sd3new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd3new2 i.pais [pweight= weight1500] if unitary == 1, vce(cluster pais)
eststo column_3

lincom 4.sd3new2#c.km_to_nid_15000 + 4.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd3new2#c.km_to_nid_15000 + 3.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B14, bottom left
margins, at(km_to_nid_15000= (0 (5) 35) sd3new2 = (1 4))
marginsplot


* (Dis) Satisfaction with public healthcare (sd6new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd6new2 i.pais [pweight= weight1500] if unitary == 1, vce(cluster pais)
eststo column_4

lincom 4.sd6new2#c.km_to_nid_15000 + 4.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd6new2#c.km_to_nid_15000 + 3.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B14, bottom right
margins, at(km_to_nid_15000= (0 (5) 35) sd6new2 = (1 4))
marginsplot


* Generating Table B8
esttab column_1 column_2 column_3 column_4 using tableB8.tex, label se pr2 aic title(Service Satisfaction, Distance to Cities of 15,000 Inhabitants, Approval of the President/Prime Minister (Only Unitary Countries))
eststo clear


********************************************************************************
***           Appendix Table B9 and Appendix Figures B15 and B16             ***
********************************************************************************

** MAIN MODEL using satisfaction with each service [Mexico Sample]:

* (Dis) Satisfaction with the police (pole2n: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##pole2n i.prov if pais == 1, vce(cluster prov)
eststo column_1

lincom 4.pole2n#c.km_to_nid_15000 + 4.pole2n#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.pole2n#c.km_to_nid_15000 + 3.pole2n#c.km_to_nid_15000#c.km_to_nid_15000

* (Dis) Satisfaction with trasportation infrastructure (sd2new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd2new2 i.prov if pais == 1, vce(cluster prov)
eststo column_2

lincom 4.sd2new2#c.km_to_nid_15000 + 4.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd2new2#c.km_to_nid_15000 + 3.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B15, top right
margins, at(km_to_nid_15000= (0 (5) 25) sd2new2 = (1 4))
marginsplot

* (Dis) Satisfaction with public schools (sd3new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd3new2 i.prov if pais == 1, vce(cluster prov)
eststo column_3

lincom 4.sd3new2#c.km_to_nid_15000 + 4.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd3new2#c.km_to_nid_15000 + 3.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B15, bottom left
margins, at(km_to_nid_15000= (0 (5) 25) sd3new2 = (1 4))
marginsplot

* (Dis) Satisfaction with public healthcare (sd6new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd6new2 i.prov if pais == 1, vce(cluster prov)
eststo column_4

lincom 4.sd6new2#c.km_to_nid_15000 + 4.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd6new2#c.km_to_nid_15000 + 3.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B15, bottom right
margins, at(km_to_nid_15000= (0 (5) 25) sd6new2 = (1 4))
marginsplot


** MAIN MODEL using satisfaction with each service [Colombia Sample]:

* (Dis) Satisfaction with the police (pole2n: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##pole2n i.prov if pais == 8, vce(cluster prov)
eststo column_5

lincom 4.pole2n#c.km_to_nid_15000 + 4.pole2n#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.pole2n#c.km_to_nid_15000 + 3.pole2n#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B15, top right
margins, at(km_to_nid_15000= (0 (5) 20) pole2n = (1 4))
marginsplot

* (Dis) Satisfaction with trasportation infrastructure (sd2new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd2new2 i.prov if pais == 8, vce(cluster prov)
eststo column_6

lincom 4.sd2new2#c.km_to_nid_15000 + 4.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd2new2#c.km_to_nid_15000 + 3.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B15, top right
margins, at(km_to_nid_15000= (0 (5) 20) sd2new2 = (1 4))
marginsplot

* (Dis) Satisfaction with public schools (sd3new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd3new2 i.prov if pais == 8, vce(cluster prov)
eststo column_7

lincom 4.sd3new2#c.km_to_nid_15000 + 4.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd3new2#c.km_to_nid_15000 + 3.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B15, bottom left
margins, at(km_to_nid_15000= (0 (5) 20) sd3new2 = (1 4))
marginsplot

* (Dis) Satisfaction with public healthcare (sd6new2: 1=very satisfied, 4=very disatisfied)
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##sd6new2 i.prov if pais == 8, vce(cluster prov)
eststo column_8

lincom 4.sd6new2#c.km_to_nid_15000 + 4.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd6new2#c.km_to_nid_15000 + 3.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000

* Appendix Figure B15, bottom right
margins, at(km_to_nid_15000= (0 (5) 20) sd6new2 = (1 4))
marginsplot

* Generating Table B9
esttab column_1 column_2 column_3 column_4 column_5 column_6 column_7 column_8 using tableB9.tex, label se pr2 aic title(Service Satisfaction, Distance to Cities of 15,000 Inhabitants, Approval of the President/Prime Minister (Decentralized Countries))
eststo clear


********************************************************************************
***                            Appendix Table C1                             ***
********************************************************************************
* Alternative mechanisms: INFRAX, from Luna and Soifer (2017); Clientelism (Vote Buying); Issue Salience 

* INFRAX (Luna and Soifer, 2017)
xi: reg infrax c.km_to_nid_15000##c.km_to_nid_15000 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_1

lincom km_to_nid_15000 + c.km_to_nid_15000#c.km_to_nid_15000

* Clientelism (Actually vote buying)
xi: reg clientelism1 c.km_to_nid_15000##c.km_to_nid_15000 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_2

lincom km_to_nid_15000 + c.km_to_nid_15000#c.km_to_nid_15000

* Saliency 
xi: reg ssalience c.km_to_nid_15000##c.km_to_nid_15000 i.pais [pweight= weight1500], vce(cluster pais)
eststo column_3

lincom km_to_nid_15000 + c.km_to_nid_15000#c.km_to_nid_15000

* Alternative Mechanisms 
esttab column_1 column_2 column_3 using tableC1.tex, label se r2 title(First Stage of the Mediation Analysis (Alternative Mechanisms))
eststo clear


********************************************************************************
***                    Appendix Figure C1 and Table C2                       ***
********************************************************************************
* DEFERENCE TO HIERARCHY

*Average service satisfaction
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##c.sat_avg c.dh_c1##c.sat_avg i.pais [pweight= weight1500], vce(cluster pais)
eststo m_dh_sat

* Distance mediating satisfaction:
lincom sat_avg + c.sat_avg#c.km_to_nid_15000 + c.sat_avg#c.km_to_nid_15000#c.km_to_nid_15000
lincom c.sat_avg#c.km_to_nid_15000 + c.sat_avg#c.km_to_nid_15000#c.km_to_nid_15000

* sc_c1 mediating satisfaction:
lincom sat_avg + c.dh_c1#c.sat_avg

margins, at(sat_avg= (1.75 (.25) 3.25) km_to_nid_15000 = (0 35))
marginsplot

margins, at(km_to_nid_15000= (0 (5) 35) sat_avg = (1.75 3.25))
marginsplot


* Satisfaction with the Police 
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##i.pole2n c.dh_c1##i.pole2n i.pais [pweight= weight1500], vce(cluster pais)
eststo m_dh_pol

* Distance mediating satisfaction:
lincom 4.pole2n + 4.pole2n#c.km_to_nid_15000 + 4.pole2n#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.pole2n + 3.pole2n#c.km_to_nid_15000 + 3.pole2n#c.km_to_nid_15000#c.km_to_nid_15000

* deference to hiearchy mediating satisfaction:
lincom 4.pole2n + 4.pole2n#c.dh_c1
lincom 3.pole2n + 3.pole2n#c.dh_c1

margins, at(pole2n= (1 (1) 4) km_to_nid_15000 = (0 35))
marginsplot

margins, at(km_to_nid_15000= (0 (5) 35) pole2n = (1 4))
marginsplot



* Satisfaction with Transportation Infrastructure
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##i.sd2new2 c.dh_c1##i.sd2new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo m_dh_inf

* Distance mediating satisfaction:
lincom 4.sd2new2 + 4.sd2new2#c.km_to_nid_15000 + 4.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd2new2 + 3.sd2new2#c.km_to_nid_15000 + 3.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000

* deference to hiearchy mediating satisfaction:
lincom 4.sd2new2 + 4.sd2new2#c.dh_c1
lincom 3.sd2new2 + 3.sd2new2#c.dh_c1

margins, at(sd2new2= (1 (1) 4) km_to_nid_15000 = (0 35))
marginsplot

margins, at(km_to_nid_15000= (0 (5) 35) sd2new2 = (1 4))
marginsplot


* Satisfaction with Education
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##i.sd3new2 c.dh_c1##i.sd3new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo m_dh_edu

* Distance mediating satisfaction:
lincom 4.sd3new2 + 4.sd3new2#c.km_to_nid_15000 + 4.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd3new2 + 3.sd3new2#c.km_to_nid_15000 + 3.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000

* deference to hiearchy mediating satisfaction:
lincom 4.sd3new2 + 4.sd3new2#c.dh_c1
lincom 3.sd3new2 + 3.sd3new2#c.dh_c1

margins, at(sd3new2= (1 (1) 4) km_to_nid_15000 = (0 35))
marginsplot

margins, at(km_to_nid_15000= (0 (5) 35) sd3new2 = (1 4))
marginsplot



* Satisfaction with Healthcare
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##i.sd6new2 c.dh_c1##i.sd6new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo m_dh_hel

* Distance mediating satisfaction:
lincom 4.sd6new2 + 4.sd6new2#c.km_to_nid_15000 + 4.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd6new2 + 3.sd6new2#c.km_to_nid_15000 + 3.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000

* deference to hiearchy mediating satisfaction:
lincom 4.sd6new2 + 4.sd6new2#c.dh_c1
lincom 3.sd6new2 + 3.sd6new2#c.dh_c1

margins, at(sd6new2= (1 (1) 4) km_to_nid_15000 = (0 35))
marginsplot

margins, at(km_to_nid_15000= (0 (5) 35) sd6new2 = (1 4))
marginsplot


* Generating Table C2

esttab m_dh_sat m_dh_pol m_dh_inf m_dh_edu m_dh_hel tableC2.tex, label se r2 title(Mechanism: Deference to Hierarchy)

eststo clear



********************************************************************************
***                    Appendix Figure C2 and Table C3                       ***
********************************************************************************
* LOW POLITICAL EFFICACY

* Average Service Satisfaction
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##c.sat_avg c.mech4_c1##c.sat_avg i.pais [pweight= weight1500], vce(cluster pais)
eststo m_pe_sat
* Distance mediating satisfaction:
lincom sat_avg + c.sat_avg#c.km_to_nid_15000 + c.sat_avg#c.km_to_nid_15000#c.km_to_nid_15000
lincom c.sat_avg#c.km_to_nid_15000 + c.sat_avg#c.km_to_nid_15000#c.km_to_nid_15000

* sc_c1 mediating satisfaction:
lincom sat_avg + c.mech4_c1#c.sat_avg

margins, at(sat_avg= (1.75 (.25) 3.25) km_to_nid_15000 = (0 35))
marginsplot

margins, at(km_to_nid_15000= (0 (5) 35) sat_avg = (1.75 3.25))
marginsplot

* Satisfaction with the Police 
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##i.pole2n c.mech4_c1##i.pole2n i.pais [pweight= weight1500], vce(cluster pais)
eststo m_pe_pol

* Distance mediating satisfaction:
lincom 4.pole2n + 4.pole2n#c.km_to_nid_15000 + 4.pole2n#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.pole2n + 3.pole2n#c.km_to_nid_15000 + 3.pole2n#c.km_to_nid_15000#c.km_to_nid_15000

* deference to hiearchy mediating satisfaction:
lincom 4.pole2n + 4.pole2n#c.mech4_c1
lincom 3.pole2n + 3.pole2n#c.mech4_c1

margins, at(pole2n= (1 (1) 4) km_to_nid_15000 = (0 35))
marginsplot

margins, at(km_to_nid_15000= (0 (5) 35) pole2n = (1 4))
marginsplot


* Satisfaction with Transportation Infrastructure
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##i.sd2new2 c.mech4_c1##i.sd2new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo m_pe_inf

* Distance mediating satisfaction:
lincom 4.sd2new2 + 4.sd2new2#c.km_to_nid_15000 + 4.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd2new2 + 3.sd2new2#c.km_to_nid_15000 + 3.sd2new2#c.km_to_nid_15000#c.km_to_nid_15000

* deference to hiearchy mediating satisfaction:
lincom 4.sd2new2 + 4.sd2new2#c.mech4_c1
lincom 3.sd2new2 + 3.sd2new2#c.mech4_c1

margins, at(sd2new2= (1 (1) 4) km_to_nid_15000 = (0 35))
marginsplot

margins, at(km_to_nid_15000= (0 (5) 35) sd2new2 = (1 4))
marginsplot


* Satisfaction with Education
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##i.sd3new2 c.mech4_c1##i.sd3new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo m_pe_edu

* Distance mediating satisfaction:
lincom 4.sd3new2 + 4.sd3new2#c.km_to_nid_15000 + 4.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd3new2 + 3.sd3new2#c.km_to_nid_15000 + 3.sd3new2#c.km_to_nid_15000#c.km_to_nid_15000

* deference to hiearchy mediating satisfaction:
lincom 4.sd3new2 + 4.sd3new2#c.mech4_c1
lincom 3.sd3new2 + 3.sd3new2#c.mech4_c1


margins, at(sd3new2= (1 (1) 4) km_to_nid_15000 = (0 35))
marginsplot

margins, at(km_to_nid_15000= (0 (5) 35) sd3new2 = (1 4))
marginsplot


* Satisfaction with Healthcare
xi: logit exec_perf c.km_to_nid_15000##c.km_to_nid_15000##i.sd6new2 c.mech4_c1##i.sd6new2 i.pais [pweight= weight1500], vce(cluster pais)
eststo m_pe_hel

* Distance mediating satisfaction:
lincom 4.sd6new2 + 4.sd6new2#c.km_to_nid_15000 + 4.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000
lincom 3.sd6new2 + 3.sd6new2#c.km_to_nid_15000 + 3.sd6new2#c.km_to_nid_15000#c.km_to_nid_15000

* deference to hiearchy mediating satisfaction:
lincom 4.sd6new2 + 4.sd6new2#c.mech4_c1
lincom 3.sd6new2 + 3.sd6new2#c.mech4_c1

margins, at(sd6new2= (1 (1) 4) km_to_nid_15000 = (0 35))
marginsplot

margins, at(km_to_nid_15000= (0 (5) 35) sd6new2 = (1 4))
marginsplot


* Generating Table C3
esttab m_pe_sat m_pe_pol m_pe_inf m_pe_edu m_pe_hel using tableC3.tex, label se r2 title(Mechanism: Low Political Efficacy)

eststo clear

********************************************************************************
